package com.dhcc.sds.busi.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;


import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.annotion.BussinessLog;

import com.dhcc.sds.busi.entity.SdsTipsRecordEntity;
import com.dhcc.sds.busi.service.ISdsTipsRecordService;


/**
 * 单病种诊疗提示记录
 * 
 * @ClassName: TipsRecordController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-08-02 08:52:32
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/tipsrecord")
public class SdsTipsRecordController extends BaseController {

	private String PREFIX = "/backend/sds/tipsrecord/";

	@Autowired
	private ISdsTipsRecordService tipsRecordService;
	

    /**
     * 跳转到单病种诊疗提示记录列表首页
     */
    @RequestMapping("")
    @Permission("tipsrecord:list")
    public String index() {
        return PREFIX + "tipsrecord.html";
    }
	
    /**
     * 跳转到新增单病种诊疗提示记录
     */
    @RequestMapping("/to_add")
    @Permission("tipsrecord:add")
    public String toAdd() {
        return PREFIX + "tipsrecord_add.html";
    }
	
	/**
     * 跳转到修改单病种诊疗提示记录
     */
    @RequestMapping("/to_update/{tipsRecordId}")
    @Permission("tipsrecord:update")
    public String toUpdate(@PathVariable Long tipsRecordId, Model model) {
        SdsTipsRecordEntity tipsRecord = this.tipsRecordService.selectById(tipsRecordId);
        model.addAttribute("tipsRecord",tipsRecord);
        return PREFIX + "tipsrecord_edit.html";
    }

    /**
     * 获取单病种诊疗提示记录列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("tipsrecord:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsTipsRecordEntity> page = new PageFactory<SdsTipsRecordEntity>().defaultPage();
        List<SdsTipsRecordEntity> result = this.tipsRecordService.page(page,params);
        page.setRecords((List<SdsTipsRecordEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增单病种诊疗提示记录
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("tipsrecord:add")
    @BussinessLog(value = "新增单病种诊疗提示记录")
    public Object add(SdsTipsRecordEntity tipsRecord) {
        if (CommonUtil.isOneEmpty(tipsRecord)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        tipsRecord.insert();
        return R.ok();
    }

    /**
     * 删除单病种诊疗提示记录
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("tipsrecord:delete")
    @BussinessLog(value = "删除单病种诊疗提示记录")
    public Object delete(@RequestParam Long tipsRecordId) {
	
        this.tipsRecordService.deleteById(tipsRecordId);

        return R.ok();
    }

    /**
     * 修改单病种诊疗提示记录
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("tipsrecord:update")
    @BussinessLog(value = "修改单病种诊疗提示记录")
    public Object update(SdsTipsRecordEntity tipsRecord) {
        if (CommonUtil.isOneEmpty(tipsRecord)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsTipsRecordEntity old = this.tipsRecordService.selectById(tipsRecord.getId());

        old.setEpisodeId(tipsRecord.getEpisodeId());
        old.setEntityId(tipsRecord.getEntityId());
        old.setTipType(tipsRecord.getTipType());
        old.setTipDate(tipsRecord.getTipDate());
        old.setTipDoc(tipsRecord.getTipDoc());
        old.setTipTimes(tipsRecord.getTipTimes());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
